<!--设置模块唯一ID-->
<div id="system_quanxianguanli_permission">
<!--列表-->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="btn-group pull-left" data-type="actionBar">
                        <button type="button" class="btn btn-default" data-action="add">添加</button>
                        <button type="button" class="btn btn-default" data-action="modify"><i class="fa fa-pencil"></i> 修改</button>
                        <button type="button" class="btn btn-default" data-action="delete"><i class="fa fa-remove"></i> 删除</button>
                    </div>
                    <div class=" pull-right" data-type="columnControl">
                    </div>
                    <div class=" pull-right " data-type="searchControl">
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="box-body">
                    <table class="table table-bordered table-striped table-hover"></table>
                </div>
            </div>
        </div>
    </div>
</section>

<script>
    USEN(function (param) {
        //模块ID(全系统唯一)
        var id = "#system_quanxianguanli_permission";
        var addId = "system_quanxianguanli_permission_add";
        var modifyId = "system_quanxianguanli_permission_modify";

        //定义页面变量
        var $el = $(id);
        var $actionBar = $el.find("[data-type=actionBar]");
        var tableId = id + " table.table";
        var $table = $(tableId);
        var myTable;

      //定义增\删\改 方法
        var editor = {
            add:function(){
                USEN.load(USEN.router[addId], param);
            },
            remove: function (data) {
            	//alert('data.subDeptName='+data.subDeptName+';data.subDeptId='+data.subDeptId);
                USEN.modal({
                    title: "提示",
                    content: "是否删除这条数据?",
                    submitTxt: "删除",
                    submitCb: function ($el) {
                        $.ajax({
                            url: "/renliziyuan/department/remove",
                            data:{deptId:data.subDeptId, roleId:data.subRoleId},
                            success: function (result) {
                                USEN.notifyAlert({
                                    title: "提示:",
                                    content: '删除成功.'
                                });
                                $el.modal("hide");
                                if (myTable) myTable.ajax.reload();
                            }
                        })
                    }
                })
            },
            modify: function (data) {
                USEN.load(USEN.router[modifyId], data);
            }
        };
      
        $actionBar.find("[data-action]").on("click", function () {
            var action = $(this).data("action");
            var $selected = $table.find('tr.selected');
            switch (action) {
                case "add" :
                    editor.add();
                    break;
                case "modify" :
                    if ($selected.length > 0) {
                        editor.modify(myTable.row($selected).data());
                    } else {
                        //提示"请选中要修改的行"
                        USEN.modal({
                            title: "提示",
                            content: "请选中要修改的行.",
                            cancelBtn: true,
                            cancelTxt: "关闭"
                        })
                    }
                    break;
                case "delete" :
                    if ($selected.length > 0) {
                        editor.remove(myTable.row($selected).data());
                    } else {
                        //提示"请选中要删除的行"
                        USEN.modal({
                            title: "提示",
                            content: "请选中要删除的行.",
                            cancelBtn: true,
                            cancelTxt: "关闭"
                        })
                    }
                    break;
            }
        });
        
        //初始化datatable数据列表
        myTable = new USEN.Datatable({
            //设置ID
            "id": tableId,
            onItemAction: function ($tr, action) {
                switch (action) {
                    case "modify" :
                        editor.modify(this.row($tr).data());
                        break;
                    case "delete" :
                        editor.remove(this.row($tr).data());
                        break;
                }
            },
            //配置服务
//            "ajax": "/system/rolesMenu/getRolesMenuByRolesId?rolesId=" + param.id,
            "ajax":"./simdata/common_table_ation.json",
            //列设置
            "columns": [
				{
				    data: null,
				    defaultContent: '',
				    className: 'select-checkbox',
				    orderable: false, searchable: false,
				    width: "30px"
				},
				{ "title": "操作", "data": null, orderable: false, searchable: false, width: '200px', render: function (data, type, full, meta) {
				    return  '<button data-item-action="modify" class="btn btn-primary">修改</button>&nbsp;&nbsp;' +
				            '<button data-item-action="delete" class="btn btn-danger">删除</button>'
				}},
                { "title": "菜单名", "data": "p1" },
                { "title": "菜单操作", "data": "p2"}
            ]
        })
    });
</script>
</div>